package com.gao.controller;

import com.gao.entity.Product;
import com.gao.service.OrderService;
import com.gao.service.ProductService;
import com.gao.util.ResultVO;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author gao
 * @time 2022/11/26 14:53:53
 */
@RestController
@RequiredArgsConstructor
public class TestController {

    @NonNull
    private ProductService productService;

    @NonNull
    private OrderService orderService;

    @GetMapping("/orders/message")
    public String message() {
        orderService.getOrderDetailByOrderId(1);
        return "message: " + System.currentTimeMillis();
    }

    @GetMapping("/orders/message2")
    public String message2() {
        orderService.getOrderDetailByOrderId(1);
        return "message2: " + System.currentTimeMillis();
    }

    @PreAuthorize("hasAuthority('product:save')")
    @GetMapping("/orders/message3")
    public String message3() {
        return "message3: " + System.currentTimeMillis();
    }

    @GetMapping("/orders/message4")
    public String message4() {
        return "message4: " + System.currentTimeMillis();
    }

    @GetMapping("/orders/message5")
    public String message5() {
        return "message5: " + System.currentTimeMillis();
    }

    @GetMapping("/orders/message6")
    public String message6() {
        return "message6: " + System.currentTimeMillis();
    }

    @GetMapping("/orders/message7")
    public String message7() {
        return "message7: " + System.currentTimeMillis();
    }

    @GetMapping("/orders/lb")
    public ResultVO testLoadBalance() {
        ResultVO resultVO = productService.testLoadBalance();
        return resultVO;
    }

    @GetMapping("orders/testObjectParam")
    public ResultVO testObjectParam() {
        Product product = new Product();
        product.setProductId(4);
        product.setProductName("光年之外");
        product.setPrice(60d);
        product.setStock(100);
        ResultVO resultVO = productService.testObjectParam(product);
        return resultVO;
    }
}